#include "debugLog.h"

DebugLog::DebugLog()
{

}





void DebugLog::write(QString text){

#ifdef Q_OS_ANDROID
    QString outdir = "/storage/emulated/0/Download/Log/";
#else
    QString outdir = "./Log";

#endif

    QDir dir;
    if (!dir.exists(outdir)) {
        dir.mkpath(outdir); // 创建目录
    }

    QString date= QDateTime::currentDateTime().toString("yyyyMMdd");
    QString outpath = outdir + "/96PCR-log-" + date + ".txt";
    //qDebug() << "Debug路径：" <<outpath;

    QFile file(outpath);
    file.open(QIODevice::Append);
    QString currentTime = QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm-ss");
    file.write((currentTime + "   " + text + "\n").toUtf8());
    file.close();

    return;

}


void DebugLog::funcStart(QString context, QString text){

    if(DEBUG_MODE < 3) return;
    write("[DEBUG] " + context + " >>> [Start] " + text);

}

void DebugLog::funcEnd(QString context, QString text){

    if(DEBUG_MODE < 3) return;
    write("[DEBUG] " + context + " >>> [End] " + text);
}

void DebugLog::debug(QString context, QString text){

    if(DEBUG_MODE < 3) return;
    write("[DEBUG] " + context + " >>> " + text);
}

void DebugLog::info(QString context, QString text){

    if(DEBUG_MODE < 2) return;
    write("[INFO] " + context + " >>> " + text);
}

void DebugLog::error(QString context, QString text){

    if(DEBUG_MODE < 1) return;
    write("[ERROR] " + context + " >>> " + text);
}

void DebugLog::warning(QString context, QString text){

    if(DEBUG_MODE < 1) return;
    write("[WARNI] " + context + " >>> " + text);
}
